package io.renren.common.utils;

import com.alibaba.fastjson.JSONObject;

import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.HashMap;
import java.util.Map;

public class LiveUtils {
    /**
     * 域名转ip
     **/
    public static String IpConvert(String domainName) {
        String ip = domainName;
        try {
            ip = InetAddress.getByName(domainName).getHostAddress();
        } catch (UnknownHostException e) {
            e.printStackTrace();
            return domainName;
        }
        return ip;
    }

    /**
     *参数非空校验
     **/
    public static boolean isNullParameters(JSONObject cameraJson, String[] isNullArr) {
        Map<String, Object> checkMap = new HashMap<>();
        // 空值校验
        for (String key : isNullArr) {
            if (null == cameraJson.get(key) || "".equals(cameraJson.get(key))) {
                return false;
            }
        }
        return true;
    }

    /**
     *参数ip格式校验
     **/
    public static boolean isTrueIp(String ip) {
        return ip.matches("([1-9]|[1-9]\\d|1\\d{2}|2[0-4]\\d|25[0-5])(\\.(\\d|[1-9]\\d|1\\d{2}|2[0-4]\\d|25[0-5])){3}");
    }

}
